<template>
	<view>
		<view style="height: 18upx;"></view>
		<view class="cell-view">
			<view class="cell-item" style="padding: 24upx 0;">
				<view class="label-text">新消息通知</view>
				<view style="margin-right: -20upx;">
					<switch :checked="notificationFlag" style="transform:scale(0.7);" @change="onSwitchChange" color="#FF2615" />
				</view>
			</view>
		</view>
		<view class="cell-view">
			<navigator url="/pages/updatePhone/updatePhone" hover-class="none" class="cell-item">
				<view class="label-text">更换手机</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
			<navigator url="/pages/updatePassword/updatePassword?editType=10" hover-class="none" class="cell-item">
				<view class="label-text">修改密码</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
			<navigator url="/pages/updatePassword/updatePassword?editType=20" hover-class="none" class="cell-item">
				<view class="label-text">支付密码</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
			<navigator url="/pages/logoutAccount/logoutAccount" hover-class="none" class="cell-item">
				<view class="label-text">注销账号</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
		</view>
		<view class="cell-view">
			<navigator url="/pages/agreement/agreement?key=USER_AGREEMENT" hover-class="none" class="cell-item">
				<view class="label-text">用户协议</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
			<navigator url="/pages/agreement/agreement?key=PRIVACY_POLICY" hover-class="none" class="cell-item">
				<view class="label-text">隐私政策</view>
				<uni-icons type="right" color="#7B7B9B"></uni-icons>
			</navigator>
		</view>

		<FloatView>
			<FloatButton @click="onUserOut" :columnStyle="columnStyle">退出登录</FloatButton>
		</FloatView>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				notificationFlag: false,
				columnStyle: 'width: 580rpx;background: transparent; border: 1px solid #FF2615;color: #FF2615;'
			}
		},
		onLoad() {},
		onShow() {},
		methods: {
			async onSwitchChange(event) {
				uni.$util.showLoading()
				await uni.$api.updateUserInfo({
					pushFlag: this.notificationFlag ? '10' : '20'
				}).finally(uni.finally)
				uni.$util.showSuccess()
			},
			async getUserInfo() {
				uni.$util.showLoading()
				const res = await uni.$api.getUserInfo().finally(uni.finally)
				this.notificationFlag = res.data.notificationFlag == '10'
			},
			onUserOut() {
				uni.setStorageSync('token', '')
				uni.reLaunch({
					url: '/pages/login/login'
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.cell-view {
		width: 707rpx;
		margin: 0 auto;
		background: #FFFFFF;
		padding: 0 40upx;
		border-radius: 14rpx;

		.cell-item {
			width: 100%;
			padding: 34upx 0;
			@extend .row-between;

			.label-text {
				font-size: 29rpx;
				font-weight: 400;
				color: #2C1101;
			}
		}

		.cell-item+.cell-item {
			border-top: 1rpx solid #F7E8E4;
		}

	}

	.cell-view+.cell-view {
		margin-top: 18upx;
	}
</style>